
package com.dog.basics.service.wishwash.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dog.basics.bean.model.wishwash.DogHxDev;
import com.dog.basics.dao.wishwash.DogHxDevMapper;
import com.dog.basics.dao.wishwash.DogHxFieldMapper;
import com.dog.basics.bean.dto.api.wishwash.ApiDogHxFieldPriceFromDto;
import com.dog.basics.bean.vo.api.wishwash.ApiDogHxFieldPriceVo;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dog.basics.bean.model.wishwash.DogHxFieldPrice;
import com.dog.basics.dao.wishwash.DogHxFieldPriceMapper;
import com.dog.basics.service.wishwash.DogHxFieldPriceService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 场地价格设置
 *
 * @author cy code generator
 * @date 2021-07-09 17:40:27
 */
@Service
@AllArgsConstructor
public class DogHxFieldPriceServiceImpl extends ServiceImpl<DogHxFieldPriceMapper, DogHxFieldPrice> implements DogHxFieldPriceService {

    private DogHxDevMapper devMapper;

    /**
     * @Description: 分页App
     * @Param: status
     * @return: IPage
     * @author cy code generator
     * @date 2021-07-09 17:40:27
     */
    @Override
    public ApiDogHxFieldPriceVo getApiFildPriceVo(ApiDogHxFieldPriceFromDto obj) {
        // 根据设备查询场地信息
        DogHxDev hxDev = devMapper.selectById(obj.getDevId());
        Validator.validateNotNull(hxDev, "dev.no.fileld.error");
        Validator.validateNotNull(hxDev.getFieldId(), "dev.no.fileld.error");
        Validator.validateNotEqual(hxDev.getFieldId(), 0L,"dev.no.fileld.error");
        // API - 分页查询数据信息
        List<DogHxFieldPrice> fieldPrices = this.list(Wrappers.<DogHxFieldPrice>lambdaQuery()
                .eq(DogHxFieldPrice::getFileldId, hxDev.getFieldId())
                .eq(DogHxFieldPrice::getDevType,obj.getDevType())
                .eq(DogHxFieldPrice::getNodeDevSize,obj.getNodeDevSize())
                .eq(ObjectUtil.isNotNull(obj.getNodeTemperatureOption()),DogHxFieldPrice::getNodeTemperatureOption,obj.getNodeTemperatureOption())
                .orderBy(Boolean.TRUE, obj.getIsOrderByAvg(), DogHxFieldPrice::getCreateTime));
        // 判断是否有当前机器的价格 - 种类
        Validator.validateTrue(CollUtil.isNotEmpty(fieldPrices), "current.dev.no.price.set");
        return BeanUtil.toBean(fieldPrices.get(0), ApiDogHxFieldPriceVo.class);
    }



}
